import { connect } from 'umi';
import React, { useRef } from 'react';

import '../common/style.less';
import { SchemaManage } from '@/components/SchemaComponent';
import { useDocumentationManage } from '../common/useDocumentationManage';
import { SourceManageAPI } from '../../SourceManage/common/type';
import { DBZ_STATE } from '../common/Format';
import { RevokeModal } from '../../Acomponents/RevokeModal';

const DocumentationManageView: React.FC<SourceManageAPI.IManageType> = ({ curRes, locationProps }) => {
  const { tableProps, searchProps, actionList, prefixCls, state, change } = useDocumentationManage(curRes, locationProps);
  const { invalidState } = state;
  const { setInvalidState, reloadRequests } = change;
  return (
    <div className={prefixCls + '-RootDivBox'}>
      <SchemaManage ref={useRef()} searchProps={searchProps as any} actionList={actionList} tableProps={tableProps as any} />
      {/* 撤销 */}
      {invalidState?.isShow && (
        <RevokeModal
          resObj={invalidState?.resObj}
          revokeRequestUrl={'/purchaseSourceController/invalid'}
          onClose={() => setInvalidState({})}
          reqBody={{ state: DBZ_STATE() }}
          modalTip={
            <div style={{ color: '#000' }}>
              确认是否撤销【<span style={{ color: 'red' }}>{invalidState?.resObj?.packName}</span>】的审核, 撤销后可重新提交！
            </div>
          }
          reloadRequest={reloadRequests}
        />
      )}
    </div>
  );
};

export default connect(({ baseLogin }: Record<string, any>) => ({
  curRes: baseLogin?.permissions,
}))(DocumentationManageView);
